package com.hyh.menu;

import java.util.ArrayList;
import java.util.Iterator;

public class Menu extends MenuComponent {

	private ArrayList<MenuComponent> menuComponents = new ArrayList<>();
	private String name;
	private String description;
	
	
	public Menu(String name, String description) {
		super();
		this.name = name;
		this.description = description;
	}

	@Override
	public void add(MenuComponent menuComponent) {
		menuComponents.add(menuComponent);
	}

	@Override
	public void remove(MenuComponent menuComponent) {
		if(menuComponents.contains(menuComponent)){
			menuComponents.remove(menuComponent);
		}
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void print() {
		System.out.println(name);
		System.out.println(description);
		Iterator<MenuComponent> iterator = menuComponents.iterator();
		while(iterator.hasNext()){
			MenuComponent menuComponent = iterator.next();
			menuComponent.print();
		}
	}

	
}
